package com.example.tools.security.configure;

import com.example.tools.security.expression.MallMethodSecurityExpressionHandler;
import com.example.tools.security.handler.MallAccessDeniedHandler;
import com.example.tools.security.handler.MallAuthenticationEntryPoint;
import com.example.tools.security.properties.MallSecurityProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.security.access.expression.method.MethodSecurityExpressionHandler;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration;

/**
 * Description:
 *
 * @author Yang
 * create time 2021-08-23 20:55
 * @since 0.0.1
 */
@EnableGlobalMethodSecurity(prePostEnabled = true)
@EnableConfigurationProperties(MallSecurityProperties.class)
public class MallSecurityAutoConfigure extends GlobalMethodSecurityConfiguration {

    @Bean
    @ConditionalOnMissingBean(name = "accessDeniedHandler")
    public MallAccessDeniedHandler accessDeniedHandler() {
        return new MallAccessDeniedHandler();
    }

    @Bean
    @ConditionalOnMissingBean(name = "authenticationEntryPoint")
    public MallAuthenticationEntryPoint authenticationEntryPoint() {
        return new MallAuthenticationEntryPoint();
    }

    @Bean
    public MallSecurityInterceptorConfigure mallSecurityInterceptorConfigure() {
        return new MallSecurityInterceptorConfigure();
    }

    @Override
    protected MethodSecurityExpressionHandler  createExpressionHandler() {
        return new MallMethodSecurityExpressionHandler();
    }
}